<include file='Common:header' />
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
	<!-- #section:basics/sidebar -->
	<include file='Common:left' />
	<!-- /section:basics/sidebar -->
	<div class="main-content">
		<div class="main-content-inner">
			<div class="page-content">
				<!--主题-->
				<div class="page-header">
					<h1>
						您当前操作
						<small>
							<i class="ace-icon fa fa-angle-double-right"></i>
							修改文章
						</small>
					</h1>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<form class="form-horizontal" name="form0" id="form0" method="post" action="{:U('news_runedit')}"  enctype="multipart/form-data">
							<input type="hidden" name="n_id" id="n_id" value="{$news_list.n_id}" />

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章所属主栏目： </label>
								<div class="col-sm-10">
									<select name="news_columnid"  class="col-sm-3 " >
										<option value="">请选择所属栏目</option>
										<foreach name="menu" item="vo">
											<option value="{$vo.id}"  <if condition="$vo.id eq $news_list['news_columnid']">selected</if> <if condition="$vo.menu_type eq 1">disabled class="bgccc"<else/>class="bgc"</if>>{$vo.lefthtml}{$vo.menu_name} <if condition="$vo.menu_type eq 1">(频道页)</if></option>
										</foreach>
									</select>
								</div>
							</div>
							<div class="space-4"></div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章名称：  </label>
								<div class="col-sm-10">
									<input type="text" name="news_title" id="news_title"  value="{$news_list.news_title}"   class="col-xs-10 col-sm-6"/>
									<input type="text" name="news_titleshort" id="news_titleshort"  value="{$news_list.news_titleshort}" placeholder="简短标题，建议6~12字数" class="col-xs-10 col-sm-4" style="margin-left:10px;" />
                                            <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle" id="resone"></span>
											</span>
								</div>
							</div>
							<div class="space-4"></div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章属性：  </label>
								<div class="checkbox">
									<foreach name='diyflag' item='diyflag'>
										<label id="news_flag_{$diyflag.diyflag_value}">
											<input <if condition="strstr($news_list['news_flag'],$diyflag['diyflag_value']) eq true">checked</if> class="ace ace-checkbox-2" name="news_flag[]" type="checkbox" id="news_flag_va{$diyflag.diyflag_value}" value="{$diyflag.diyflag_value}" />
											<span class="lbl"> {$diyflag.diyflag_name}</span>
										</label>
									</foreach>
								</div>
							</div>
							<div class="space-4"></div>
							<div class="form-group" id="pptaddress">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 跳转地址：  </label>
								<div class="col-sm-10">
									<input type="text" name="news_zaddress" id="news_zaddress"  value="{$news_list.news_zaddress}"   placeholder="输入页面跳转地址" class="col-xs-10 col-sm-6" />
                                            <span class="help-inline col-xs-12 col-sm-6">
												<span class="middle">正确格式：http:// 开头</span>
											</span>
								</div>
							</div>
							<div class="form-group" id="cpprice">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 产品价格：  </label>
								<div class="col-sm-10">
									<input type="text" name="news_cpprice" id="news_cpprice"  value="{$news_list.news_cpprice}"   placeholder="输入产品价格" class="col-xs-10 col-sm-6" />
								</div>
							</div>
							<div class="space-4"></div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章关键字：  </label>
								<div class="col-sm-10">
									<input type="text" name="news_key" id="news_key"  value="{$news_list.news_key}"  placeholder="输入文章关键字，以英文,逗号隔开" class="col-xs-10 col-sm-6" />
								</div>
							</div>
							<div class="space-4"></div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章来源：  </label>
								<div class="col-sm-10">
									<input type="text" name="news_source" id="news_source"  value="{$news_list.news_source}" class="col-xs-10 col-sm-2" />
									<label class="input_last">
										常用：
										<volist name="source" id="k">
											<a class="btn btn-minier btn-yellow" href="javascript:;" onclick="return souadd('{$k.source_name}');" >{$k.source_name}</a>&nbsp;
										</volist>
									</label>
								</div>
							</div>
							<div class="space-4"></div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 封面图片上传： </label>
								<div class="col-sm-10">
									<input type="hidden" name="checkpic" id="checkpic" value="{$news_list.news_img}" />
									<input type="hidden" name="oldcheckpic" id="oldcheckpic" value="{$news_list.news_img}" />
									<a href="javascript:;" class="file" title="点击选择所要上传的图片">
										<input type="file" name="pic_one[]" id="file0" multiple="multiple"/>
										选择上传文件
									</a>
									<span class="lbl">&nbsp;&nbsp;<img src="<if condition="$news_list.news_img neq ''">{$news_list.news_img}<else/>__PUBLIC__/img/no_img.jpg</if>" width="100" height="70" id="img0" ></span>&nbsp;&nbsp;<a href="javascript:;" onclick="return backpic('<if condition="$news_list.news_img eq ''">__PUBLIC__/img/no_img.jpg<else/>__UPLOAD__{$news_list.news_img}</if>');" title="还原修改前的图片" class="file">
									撤销修改
									</a>
											<span class="lbl">&nbsp;&nbsp;上传前先用PS处理成等比例图片后上传，默认比例100*70、600*420、800*560像素<br />
</span>
								</div>
							</div>
							<div class="space-4"></div>


							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章图集： </label>
								<div class="col-sm-10">
									<div class="radio" >
										<label>
											<input name="news_pic_type" <if condition="$news_list['news_pic_type'] eq 1">checked</if> id="news_pic_list" checked type="radio" class="ace" value="1"/>
											<span class="lbl"> 无图模式</span>
										</label>
										<label>
											<input name="news_pic_type" <if condition="$news_list['news_pic_type'] eq 2">checked</if> id="news_pic_qqlist" type="radio" class="ace" value="2"/>
											<span class="lbl"> 多图模式</span>
										</label>
										<if condition="$news_list['news_pic_type'] eq 2">
											<label>
												<span class="btn btn-minier btn-success"  data-toggle="modal" data-target="#myModal">查看已上传的图片</span>
											</label>
										</if>
									</div>
								</div>
							</div>
							<div class="space-4"></div>




							<link href="__PUBLIC__/ppy/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
							<script src="__PUBLIC__/ppy/js/fileinput.js" type="text/javascript"></script>
							<script src="__PUBLIC__/ppy/js/fileinput_locale_zh.js" type="text/javascript"></script>



							<div class="form-group" id="pic_list" <if condition="$news_list['news_pic_type'] eq 1">style="display:none"</if>>
							<div class="col-sm-10 col-sm-offset-2" style="padding-top:5px;">
								<input id="file-5" name="pic_all[]" type="file" class="file"  multiple data-preview-file-type="any" data-upload-url="#" data-preview-file-icon=""><br />
								<textarea name="news_pic_content" class="col-xs-12 col-sm-12" id="news_pic_content"  placeholder="多图对应文章说明，例如： 图片一说明 | 图片二说明 | 图片三说明    每个文字说明以 | 分割" >{$news_list['news_pic_content']}</textarea>
							</div>
					</div>
					<div class="space-4"></div>
					<!--老多图字符串-->
					<input name="pic_oldlist" type="hidden" id="pic_oldlist" type="text" size="130" value="{$news_list.news_pic_allurl}" >






					<div class="form-group">
						<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 是否审核： </label>
						<div class="col-sm-10" style="padding-top:5px;">
							<input name='news_open' id='news_open' <if condition="$news_list['news_open'] eq 1">checked</if>  value='1' class='ace ace-switch ace-switch-4 btn-flat' type='checkbox' />
							<span class="lbl">&nbsp;&nbsp;默认关闭</span>
						</div>
					</div>
					<div class="space-4"></div>

					<div class="form-group">
						<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章简介： </label>
						<div class="col-sm-9">
							<input type="text" name="news_scontent" id="news_scontent" class="col-xs-10 col-sm-10"  maxlength="100" value="{$news_list.news_scontent}"  placeholder="输入文章简介"  />
							<label class="input_last">已限制在100个字以内</label>
						</div>
					</div>
					<div class="space-4"></div>

					<div class="form-group">
						<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 文章主内容 </label>
						<div class="col-sm-10">
							<script src="__PUBLIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
							<script src="__PUBLIC__/ueditor/ueditor.all.js" type="text/javascript"></script>
							<textarea name="news_content" rows="100%" style="width:100%" id="myEditor">{$news_list.news_content}</textarea>
							<script type="text/javascript">
								var editor = new UE.ui.Editor();
								editor.render("myEditor");
							</script>
						</div>
					</div>
					<div class="space-4"></div>

					<div class="clearfix form-actions">
						<div class="col-md-offset-3 col-md-9">
							<button class="btn btn-info" type="submit">
								<i class="ace-icon fa fa-check bigger-110"></i>
								保存
							</button>

							&nbsp; &nbsp; &nbsp;
							<button class="btn" type="reset">
								<i class="ace-icon fa fa-undo bigger-110"></i>
								重置
							</button>
						</div>
					</div>
					</form>
				</div>
			</div>
			<!-- <div class="hr hr-24"></div> -->

			<include file='Common:header_nav' />

		</div><!-- /.page-content -->
	</div>
</div><!-- /.main-content -->

<include file='Common:footer' />

</div><!-- /.main-container -->
<script>
	function backpic(picurl){
		$("#img0").attr("src",picurl);//还原修改前的图片
		$("input[name='file0']").val("");//清空文本框的值
		$("input[name='oldcheckpic']").val(picurl);//清空文本框的值
	}

	$(document).ready(function(){


		$("#news_pic_list").click(function(){
			$("#pic_list").hide();
		});
		$("#news_pic_qqlist").click(function(){
			$("#pic_list").show();
		});

		if(!$("#news_flag_vaj").attr("checked")){
		$("#pptaddress").hide();
		}
		$("#news_flag_vaj").click(function(){
			$("#pptaddress").toggle(400);
		});
		
		if(!$("#news_flag_vacp").attr("checked")){
		$("#cpprice").hide();
		}
		$("#news_flag_vacp").click(function(){
			$("#cpprice").toggle(400);
		});

	});

	$(function(){
		$('#address').hide();//默认隐藏
		$('#type2').click(function(){
			$('#address').show();
		});
		$('#type1,#type3,#type4,#type5').click(function(){
			$('#address').hide();
		});
	});

	$(function(){
		$('#form0').ajaxForm({
			beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
			success: complete, // 这是提交后的方法
			dataType: 'json'
		});

		function checkForm(){
			if( '' == $.trim($('#news_title').val())){
				layer.alert('文章标题不能为空', {icon: 5}, function(index){
					layer.close(index);
					$('#news_title').focus();
				});
				return false;
			}

			if(isNaN($.trim($('#news_cpprice').val()))){
				layer.alert('价格需为数字', {icon: 5}, function(index){
					layer.close(index);
					$('#news_cpprice').focus();
				});
				return false;
			}
		}
		function complete(data){
			if(data.status==1){
				layer.alert(data.info, {icon: 6}, function(index){
					layer.close(index);
					window.location.href=data.url;
				});
			}else{
				layer.alert(data.info, {icon: 5}, function(index){
					layer.close(index);
					window.location.href="{:U('news_list')}";
				});
				return false;
			}
		}
	});
</script>
<script>
	$("#file0").change(function(){
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$("#img0").attr("src", objUrl) ;
		}
	}) ;
	//建立一個可存取到該file的url
	function getObjectURL(file) {
		var url = null ;
		if (window.createObjectURL!=undefined) { // basic
			$("#news_flag_vap").attr("checked", true);
			$("#oldcheckpic").val("nopic");
			url = window.createObjectURL(file) ;
		} else if (window.URL!=undefined) { // mozilla(firefox)
			$("#news_flag_vap").attr("checked", true);
			$("#oldcheckpic").val("nopic");
			url = window.URL.createObjectURL(file) ;
		} else if (window.webkitURL!=undefined) { // webkit or chrome
			$("#news_flag_vap").attr("checked", true);
			$("#oldcheckpic").val("nopic");
			url = window.webkitURL.createObjectURL(file) ;
		}
		return url ;
	}

	//来源
	function souadd(val){
		$('#news_source').val(val);
	}
</script>


<!-- 显示模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:80%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					操作已上传的多图
				</h4>
			</div>
			<div class="modal-body">
				<div class="row">
					<div class="col-xs-12">


						<div class="form-group">
							<div class="col-sm-10">
								<ul>
									<volist name="pic_list" id="v">

										<div class="file-preview-frame" data-fileindex="0" id="id{$i}">
											<img src="{$v}" class="file-preview-image" style="width:auto;height:160px;">
											<div class="file-thumbnail-footer">
												<div class="file-actions">
													<div class="file-footer-buttons">
														<a class="red" href="javascript:;" onclick="return delall({$i},'{$v}');" title="回收站">
															<i class="ace-icon fa fa-trash-o bigger-130"></i>
														</a>
													</div>
													<div class="clearfix"></div>
												</div>
											</div>
										</div>

									</volist>
								</ul>
							</div>
						</div>

						<div class="space-4"></div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary">
					若想取消修改，请刷新当前页面
				</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">
					关闭
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
	function delall(id,url){
		$('#id'+id).hide();
		var str=$('#pic_oldlist').val();//最原始的完整路径
		var surl=url+',';
		var pic_newold=str.replace(surl,"");
		$('#pic_oldlist').val(pic_newold);
	}
</script>
</body>
</html>
